package com.api.shopapi.mapper;

import com.api.shopapi.entity.RoomType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface RoomTypeMapper {
    @Insert("insert into room_type " +
            "(RoomTypeCode,Name,Status,InstitutionCode,Num,Price,PriceMonth) " +
            "value (#{roomType.RoomTypeCode},#{roomType.Name}," +
            "#{roomType.Status},#{roomType.InstitutionCode},#{roomType.Num},#{roomType.Price},#{roomType.PriceMonth})")
    int insert(@Param("roomType") RoomType roomType);

    @Update("update room_type set Name = #{roomType.Name}," +
            "Status=#{roomType.Status},Num=#{roomType.Num},InstitutionCode=#{roomType.InstitutionCode},Price=#{roomType.Price},PriceMonth=#{roomType.PriceMonth} " +
            "where RoomTypeCode=#{roomType.RoomTypeCode}")
    int updateByRoomTypeCode(@Param("roomType") RoomType roomType);

    @Select("select * from room_type where Name=#{name} and InstitutionCode=#{institutionCode} limit 1")
    RoomType getByNameAndInstitutionCode(@Param("name") String name,@Param("institutionCode") String institutionCode);

    @Select("select * from room_type where InstitutionCode = #{institutionCode} and Status =0 order by Num")
    List<RoomType> getListAllByInstitutionCode(@Param("institutionCode") String institutionCode);

    @Select("<script>" +
            "select * from room_type " +
            "where InstitutionCode = #{institutionCode}" +
            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status !=-1 '> " +
            "and Status = #{status} " +
            "</if>" +
            "order by Num" +
            "</script>")
    List<RoomType> getPageList(@Param("institutionCode") String institutionCode, @Param("name") String name,@Param("status") int status);

    @Select("select * from room_type where RoomTypeCode=#{roomTypeCode} limit 1")
    RoomType getByRoomTypeCode(@Param("roomTypeCode") String roomTypeCode);


    @Select("<script>" +
            "select * from room_type " +
            " where InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode}) " +
            " order by Num" +
            "</script>")
    List<RoomType> listByGovCode(@Param("governmentCode") String governmentCode);


}
